package fr.utbm.gl52.smartgrid.model.storage;

import java.util.Map;
import java.util.TreeMap;

import fr.utbm.gl52.smartgrid.model.device.Device;
import fr.utbm.gl52.smartgrid.util.properties.Properties;
import fr.utbm.gl52.smartgrid.util.properties.PropertyDouble;
import fr.utbm.gl52.smartgrid.util.properties.PropertyLong;

public abstract class AbstractStorage extends Device {
	private/* final */double powerMin;
	private/* final */double powerMax;
	private double stateOfCharge;
	private/* final */double socMin;
	private/* final */double socMax;
	private double dynamic;
	private/* final */double dynamicMin;
	private/* final */double dynamicMax;
	private long lifespan;
	private double eTotStockage;
	private StorageType storageType;

	public AbstractStorage() {
		super();
	}

	public AbstractStorage(String name, double power, double current,
			double voltage, double efficiency, double pwMin, double pwMax,
			double socMin, double socMax, double dynamicMin, double dynamicMax,
			double SOC, double dynamic, long lifetime, double eTotStock,
			StorageType stype) {
		super(name, power, current, voltage, efficiency);
		this.powerMin = pwMin;
		this.powerMax = pwMax;
		this.socMin = socMin;
		this.socMax = socMax;
		this.dynamicMin = dynamicMin;
		this.dynamicMax = dynamicMax;
		this.stateOfCharge = SOC;
		this.dynamic = dynamic;
		this.lifespan = lifetime;
		this.eTotStockage = eTotStock;
		this.storageType = stype;
	}

	public double getPowerMin() {
		return this.powerMin;
	}

	public void setPowerMin(double powerMin) {
		this.powerMin = powerMin;
	}

	public double getPowerMax() {
		return this.powerMax;
	}

	public void setPowerMax(double powerMax) {
		this.powerMax = powerMax;
	}

	public double getStateOfCharge() {
		return this.stateOfCharge;
	}

	public void setStateOfCharge(double stateOfCharge) {
		this.stateOfCharge = stateOfCharge;
	}

	public double getSocMin() {
		return this.socMin;
	}

	public void setSocMin(double socMin) {
		this.socMin = socMin;
	}

	public double getSocMax() {
		return this.socMax;
	}

	public void setSocMax(double socMax) {
		this.socMax = socMax;
	}

	public double getDynamic() {
		return this.dynamic;
	}

	public void setDynamic(double dynamic) {
		this.dynamic = dynamic;
	}

	public double getDynamicMin() {
		return this.dynamicMin;
	}

	public void setDynamicMin(double dynamicMin) {
		this.dynamicMin = dynamicMin;
	}

	public double getDynamicMax() {
		return this.dynamicMax;
	}

	public void setDynamicMax(double dynamicMax) {
		this.dynamicMax = dynamicMax;
	}

	public long getLifespan() {
		return this.lifespan;
	}

	public void setLifespan(long lifespan) {
		this.lifespan = lifespan;
	}

	public double geteTotStockage() {
		return this.eTotStockage;
	}

	public void seteTotStockage(double eTotStockage) {
		this.eTotStockage = eTotStockage;
	}

	public StorageType getStorageType() {
		return this.storageType;
	}

	public void setStorageType(StorageType storageType) {
		this.storageType = storageType;
	}

	public Map<String, Properties<?>> getProperties() {
		TreeMap<String, Properties<?>> prop = (TreeMap<String, Properties<?>>) super
				.getProperties();
		PropertyDouble p1 = new PropertyDouble(
				Messages.getString("AbstractStorage.0"), this.powerMin, false); //$NON-NLS-1$
		PropertyDouble p2 = new PropertyDouble(
				Messages.getString("AbstractStorage.1"), this.powerMax, false); //$NON-NLS-1$
		PropertyDouble p3 = new PropertyDouble(
				Messages.getString("AbstractStorage.2"), this.stateOfCharge, false); //$NON-NLS-1$
		PropertyDouble p4 = new PropertyDouble(
				Messages.getString("AbstractStorage.3"), this.socMin, false); //$NON-NLS-1$
		PropertyDouble p5 = new PropertyDouble(
				Messages.getString("AbstractStorage.4"), this.socMax, false); //$NON-NLS-1$
		PropertyDouble p6 = new PropertyDouble(
				Messages.getString("AbstractStorage.5"), this.dynamic, false); //$NON-NLS-1$
		PropertyDouble p7 = new PropertyDouble(
				Messages.getString("AbstractStorage.6"), this.dynamicMin, false); //$NON-NLS-1$
		PropertyDouble p8 = new PropertyDouble(
				Messages.getString("AbstractStorage.7"), this.dynamicMax, false); //$NON-NLS-1$

		PropertyLong pl1 = new PropertyLong(
				Messages.getString("AbstractStorage.8"), this.lifespan, false); //$NON-NLS-1$
		PropertyDouble p9 = new PropertyDouble(
				Messages.getString("AbstractStorage.9"), this.eTotStockage, false); //$NON-NLS-1$

		prop.put(p1.getName(), p1);
		prop.put(p2.getName(), p2);
		prop.put(p3.getName(), p3);
		prop.put(p4.getName(), p4);
		prop.put(p5.getName(), p5);
		prop.put(p6.getName(), p6);
		prop.put(p7.getName(), p7);
		prop.put(p8.getName(), p8);
		prop.put(pl1.getName(), pl1);
		prop.put(p9.getName(), p9);
		return prop;
	}

	public void setProperties(Map<String, Properties<?>> map) {
		this.powerMin = (Double) map
				.remove(Messages.getString("AbstractStorage.0")).getValue(); //$NON-NLS-1$
		this.powerMax = (Double) map
				.remove(Messages.getString("AbstractStorage.1")).getValue(); //$NON-NLS-1$
		this.stateOfCharge = (Double) map.remove(
				Messages.getString("AbstractStorage.2")).getValue(); //$NON-NLS-1$
		this.socMin = (Double) map
				.remove(Messages.getString("AbstractStorage.3")).getValue(); //$NON-NLS-1$
		this.socMax = (Double) map
				.remove(Messages.getString("AbstractStorage.4")).getValue(); //$NON-NLS-1$
		this.dynamic = (Double) map
				.remove(Messages.getString("AbstractStorage.5")).getValue(); //$NON-NLS-1$
		this.dynamicMin = (Double) map.remove(
				Messages.getString("AbstractStorage.6")).getValue(); //$NON-NLS-1$
		this.dynamicMax = (Double) map.remove(
				Messages.getString("AbstractStorage.7")).getValue(); //$NON-NLS-1$
		this.lifespan = (Long) map
				.remove(Messages.getString("AbstractStorage.8")).getValue(); //$NON-NLS-1$
		this.eTotStockage = (Double) map.remove(
				Messages.getString("AbstractStorage.9")).getValue(); //$NON-NLS-1$
		super.setProperties(map);
	}
}
